import 'dart:async';
import 'dart:io';

import 'package:flutter/services.dart';

class BatteryOptimization {
  static const MethodChannel _channel = const MethodChannel('com.ashlikun.battery_opt');

  static Future<bool> showEnableAutoStartSettings(String dialogTitle, String dialogBody) async {
    return await _channel.invokeMethod('showEnableAutoStart', <dynamic>[dialogTitle, dialogBody]);
  }

  static Future<bool> showDisableBatteryOptimizationSettings() async {
    if (Platform.isAndroid) {
      return await _channel.invokeMethod('showDisableBatteryOptimization');
    } else {
      return true;
    }
  }

  static Future<bool> get isAutoStartEnabled async {
    if (Platform.isAndroid) {
      return await _channel.invokeMethod("isAutoStartEnabled");
    } else {
      return true;
    }
  }

  static Future<bool> get isBatteryOptimizationDisabled async {
    if (Platform.isAndroid) {
      return await _channel.invokeMethod("isBatteryOptimizationDisabled");
    } else {
      return true;
    }
  }

  static Future<bool> get isManufacturerBatteryOptimizationDisabled async {
    if (Platform.isAndroid) {
      return await _channel.invokeMethod("isManBatteryOptimizationDisabled");
    } else {
      return true;
    }
  }

  static Future<bool> get isAllBatteryOptimizationDisabled async {
    if (Platform.isAndroid) {
      return await _channel.invokeMethod("isAllOptimizationsDisabled");
    } else {
      return true;
    }
  }

  //是否是电池省电模式
  static Future<bool> get isPowerSaveMode async {
    if (Platform.isAndroid) {
      return await _channel.invokeMethod("isPowerSaveMode");
    } else {
      return false;
    }
  }

  //是否可以交互,屏幕是否亮起
  static Future<bool> get isInteractive async {
    return await _channel.invokeMethod("isInteractive");
  }
}
